//
//  WBVisitorView.swift
//  Weibo
//
//  Created by 张俭 on 16/8/17.
//  Copyright © 2016年 张俭. All rights reserved.
//

import UIKit

class WBVisitorView: UIView {
    @IBOutlet weak fileprivate var iconView: UIImageView!
    @IBOutlet weak fileprivate var maskIconView: UIImageView!
    @IBOutlet weak fileprivate var houseView: UIImageView!
    @IBOutlet weak fileprivate var tipLabel: UILabel!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var registerButton: UIButton!
    var visitorInfo : [String:AnyObject]?{
        didSet{
            if let imageName = visitorInfo?["imageName"] as? String , imageName.characters.count > 0{
                iconView.image = UIImage(named: imageName)
                maskIconView.isHidden = true
                houseView.isHidden = true
            }else{
                startAnimation()
            }
            if let message = visitorInfo?["message"] as? String  {
                tipLabel.text = message
            }
            
        }
    }
    
    class func visitorView() -> WBVisitorView{
        let v = UINib(nibName: "WBVisitorView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! WBVisitorView
        return v
    }
}

// MARK: - 动画
private extension WBVisitorView {
     func startAnimation() {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        anim.duration = 5
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        
        iconView.layer.add(anim, forKey: nil)
    }
}
